<template>
	<view class="competionSearch conTainer">
		<view class="searchText f16">
			发起部门
		</view>
		<view>
			<uni-data-select :clear="false" v-model="value" :localdata="dataTree" @change="change"></uni-data-select>
		</view>
		<view class="searchText f16">
			距离截止
		</view>
		<view>
			<uni-data-select v-model="timevalue" :clear="false" :localdata="timeOption" @change="timechange">
			</uni-data-select>
		</view>
		<view class="searchText f16">
			专业类型
		</view>
		<view>
			<uni-data-select v-model="typevalue" :clear="false" :localdata="typeOption" @change="typechange">
			</uni-data-select>
		</view>
		<view class="button">
			<view type="primary" class="button_item f14 margin-right16" @click="reset">重置</view>
			<view type="primary" class="button_item f14" @click="search">搜索</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: '不限',
				timevalue: '0',
				typevalue: '2',
				dataTree: [],
				timeOption: [{
						value: '0',
						text: '不限'
					},
					{
						value: '1',
						text: '近一周'
					},
					{
						value: '2',
						text: '近三周'
					},
				],
				typeOption: [{
						value: '0',
						text: '文科'
					},
					{
						value: '1',
						text: '理科'
					},
					{
						value: '2',
						text: '不限'
					},
				],
				formData: {
					createDepartment: null,
					endDate: null,
					instituteType: null
				}
			}
		},
		methods: {
			search() {
				console.log(666);
				const data = this.formData
				this.$emit('closePopup')
				this.$nextTick(() => {
					this.$emit('searctReload', data)

				})
			},
			reset() {
				this.typevalue = '2'
				this.timevalue = '0'
				this.value = '不限'
				this.formData.createDepartment = null
				this.formData.endDate = null
				this.formData.instituteType = null
			},
			timechange(e) {
				switch (e) {
					case '0':
						this.formData.endDate = null
						break;
					case '1':
						this.formData.endDate = 7
						break;
					case '2':
						this.formData.endDate = 21
						break;

				}
			},
			change(e) {
				if (e == '不限') {
					this.formData.createDepartment = null
					return
				}
				this.formData.createDepartment = e
			},
			typechange(e) {

				switch (e) {
					case '0':
						this.formData.instituteType = 0
						break;
					case '1':
						this.formData.instituteType = 1
						break;
					case '2':
						this.formData.instituteType = 2
						break;

				}
			}
		},
		async created() {
			let dataTree = uni.getStorageSync("newList");
			if (!dataTree) {
				const data = {
					pageNum: 1,
					pageSize: 100,
				};

				const result = await this.$mjcrequest.request({
					url: this.$api.getInstituteDic,
					data: JSON.stringify(data),
					header: this.$aplsjsonheader,
				});
				const newList = result.pageDate.map((item) => {
					return {
						text: item.instituteName,
						value: item.instituteName,
						instituteId: item.instituteId,
					};
				});
				uni.setStorageSync("newList", newList);
				this.dataTree = newList
			} else {
				this.dataTree = dataTree
			}
		}
	}
</script>

<style scoped lang="less">
	.competionSearch {
		height: auto;
		background-color: #fff;

		.uni-select__selector {
			z-index: 99;
		}

		.button {
			display: flex;
			margin-top: 15rpx;
			justify-content: center;

			&_item {
				width: auto;
				background-color: #2ebef3;
				color: #fff;
				padding: 15rpx 35rpx;
				border-radius: 15rpx;
			}
		}



		.searchText {

			margin: 15rpx 0;
		}
	}
</style>
